/*
 * Copyright 2015 MongoDB, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package course.homework;

import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.result.DeleteResult;

import freemarker.template.Configuration;
import freemarker.template.Template;

import org.bson.Document;
import org.bson.types.ObjectId;

import spark.Request;
import spark.Response;
import spark.Route;
import spark.Spark;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static java.util.Arrays.asList;

public class MongoTest {
    public static void main(String[] args)  {
        MongoClient client = new MongoClient();
        MongoDatabase database = client.getDatabase("test");
        final MongoCollection<Document> coll = database.getCollection("test");
        
        coll.drop();
        coll.insertOne(new Document("scores",Arrays.asList(new Document("type","exam").append("score",156123),new Document("type","homework").append("score",99999))).append("other", "otherValue"));
        MongoCursor<Document> iterable = coll.find().limit(1).iterator();

        while(iterable.hasNext())
        {
        	Document next = iterable.next();
			System.out.println(next);
        }
    }
}
